package likou.tanxin;

/**
 * @Info:
 * @Author: 唐小尊
 * @Date: 2020/10/10 07:04
 */
public class _621 {
    public static void main(String[] args) {
        System.out.println(leastInterval(new char[]{'A', 'A', 'A', 'B', 'B', 'B'}, 2));

    }

    public static int leastInterval(char[] tasks, int n) {
        int[] counts = new int[26];

        for (char c : tasks) {
            counts[c - 'A'] += 1;
        }

        int max = 0;
        for (int count : counts) {
            max = Math.max(max, count);
        }

        int maxCount = 0;
        for (int count : counts) {
            if (count == max) {
                maxCount++;
            }
        }

        return Math.max((n + 1) * (max - 1) + maxCount, tasks.length);
    }
}
